﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FanaticUnitity.FfmpegZoomPictureTo300KB.Models
{
    public class Size
    {
        public int Width { get; set; }
        public int Height { get; set; }

        public int Area => Width * Height;

        public Size()
        {

        }

        public Size(int width, int height)
        {
            Width = width;
            Height = height;
        }

        public override string ToString()
        {
            return $"{Width} {Height}";
        }

        public static Size Prase(string widthXheightString)
        {
            var xIndex = widthXheightString.IndexOf('x');
            var widthStr = widthXheightString.Substring(0, xIndex);
            var height = widthXheightString.Substring(xIndex + 1, widthXheightString.Length - xIndex - 1);

            var widthValue = int.Parse(widthStr);
            var heightValue = int.Parse(height);

            return new Size(widthValue, heightValue);
        }

        public static Size operator *(Size size, double factor)
        {
            return new Size((int)(Math.Round(size.Width * factor)), (int)(Math.Round(size.Height * factor)));
        }

        public static Size operator /(Size size, double factor)
        {
            return new Size((int)(Math.Round(size.Width / factor)), (int)(Math.Round(size.Height / factor)));
        }
    }
}
